home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / HERMES / ProtMover6.1.cpt / ASCII / write.c < prev   
Text File  |  1990-05-26  |  3KB  |  126 lines

  1. /*    ASCII Transfer External for Hermes © 1990 By John Raymonds.
  2.  
  3.     Written in THINK C 4.0.1 as an example external for Hermes protocol
  4.     developers.  Use of any code shown below in any program other than
  5.     an external to be used with Hermes requires written permission from
  6.     the author:
  7.     
  8.     John Raymonds
  9.     76174,205 (Compuserve)
  10.     D3885 (AppleLink)
  11.     
  12.     Comments and suggestions are welcome.
  13.     
  14. */
  15.  
  16. #include <:Mac #includes:SerialDvr.h>
  17.  
  18. #include "Protocol.h"
  19. #include "ASCII.h"
  20.  
  21. extern ProtoRecPtr PRP;
  22. extern ProtoGloPtr PGP;
  23.  
  24. SendString(s)
  25. register unsigned char *s;
  26. {
  27.     register int i;
  28.     if (s) {
  29.         for (i = 1; i<=*s; i++) {
  30.             SendCharNow((int) *(s+i));
  31.         }
  32.     }
  33.     SendCharNow((int) '\r');
  34.     SendCharNow((int) '\n');
  35. }
  36.  
  37. SendCharNow(c)
  38. int c;
  39. {
  40.     register ProtoGloPtr pgp;
  41.     pgp = PGP;
  42.     if (pgp->wbPosA >= 0) {
  43.         /*    we can use the A buffer */
  44.         pgp->writeBuffA[pgp->wbPosA++] = c;
  45.         /*    check if the buffer is full */
  46.         if (pgp->wbPosA == WRITEBUFFSIZE) {
  47.             /*    write this buffer out and start using the other one */
  48.             FinishWrite();
  49.             pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffA);
  50.             pgp->MIOPout.ioReqCount = (long) WRITEBUFFSIZE;
  51.             if (!PRP->F.B.carrierLost) {
  52.                 PBWrite(StripAddress(&pgp->MIOPout), TRUE);
  53.             }
  54.             pgp->wbPosA = -1;
  55.         }
  56.     }
  57.     else {
  58.         /*    we can use the B buffer */
  59.         pgp->writeBuffB[pgp->wbPosB++] = c;
  60.         /*    check if the buffer is full */
  61.         if (pgp->wbPosB == WRITEBUFFSIZE) {
  62.             /*    write this buffer out and start using the other one */
  63.             FinishWrite();
  64.             pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffB);
  65.             pgp->MIOPout.ioReqCount = (long) WRITEBUFFSIZE;
  66.             if (!PRP->F.B.carrierLost) {
  67.                 PBWrite(StripAddress(&pgp->MIOPout), TRUE);
  68.             }
  69.             pgp->wbPosB = -1;
  70.         }
  71.     }
  72. }
  73.  
  74. FinishWrite()
  75. {
  76.     register ProtoRecPtr prp;
  77.     register ProtoGloPtr pgp;
  78.     prp = PRP;
  79.     pgp = PGP;
  80.     if (pgp->wbPosA < 0) {
  81.         do {
  82.             if (prp->F.B.carrierLost) {
  83.                 PBKillIO(StripAddress(&pgp->MIOPout), FALSE);
  84.                 pgp->MIOPout.ioResult = 0;
  85.             }
  86.             Return(prp->timeOut, &pgp->SSR);
  87.         } while(pgp->MIOPout.ioResult == 1);
  88.         pgp->wbPosA = 0;
  89.     }
  90.     else if (pgp->wbPosB < 0) {
  91.         do {
  92.             if (prp->F.B.carrierLost) {
  93.                 PBKillIO(StripAddress(&pgp->MIOPout), FALSE);
  94.                 pgp->MIOPout.ioResult = 0;
  95.             }
  96.             Return(prp->timeOut, &pgp->SSR);
  97.         } while(pgp->MIOPout.ioResult == 1);
  98.         pgp->wbPosB = 0;
  99.     }
  100. }
  101.  
  102. FlushWrite()
  103. {
  104.     register ProtoGloPtr pgp;
  105.     pgp = PGP;
  106.     FinishWrite();
  107.     if (pgp->wbPosA > 0) {
  108.         pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffA);
  109.         pgp->MIOPout.ioReqCount = (long) pgp->wbPosA;
  110.         if (!PRP->F.B.carrierLost) {
  111.             PBWrite(StripAddress(&pgp->MIOPout), TRUE);
  112.         }
  113.         pgp->wbPosA = -1;
  114.         FinishWrite();
  115.     }
  116.     else if (pgp->wbPosB > 0) {
  117.         pgp->MIOPout.ioBuffer = (Ptr) StripAddress(&pgp->writeBuffB);
  118.         pgp->MIOPout.ioReqCount = (long) pgp->wbPosB;
  119.         if (!PRP->F.B.carrierLost) {
  120.             PBWrite(StripAddress(&pgp->MIOPout), TRUE);
  121.         }
  122.         pgp->wbPosB = -1;
  123.         FinishWrite();
  124.     }
  125. }
  126.